package com.linkgie.galaxyframework.metadata.structure;

import javax.validation.constraints.NotBlank;

import com.linkgie.galaxyframework.metadata.DataComposite;
import com.linkgie.galaxyframework.metadata.DataEntity;
import com.linkgie.galaxyframework.metadata.DataField;
import com.linkgie.galaxyframework.metadata.DataInterface;
import com.linkgie.galaxyframework.metadata.DataKey;
import com.linkgie.galaxyframework.metadata.DataLabel;
import com.linkgie.galaxyframework.metadata.DataReference;
import com.linkgie.galaxyframework.metadata.DataType;
import com.linkgie.galaxyframework.metadata.DefaultBoolean;

@DataInterface
@DataEntity
public class DataModelMetadata implements ModelBaseSettings, ModelFieldListSettings, ModelSettings, DataTypeInfo {

	/**
	 * 数据模型的唯一名称；
	 * 
	 * 具有全局唯一性；
	 */
	@NotBlank
	@DataKey
	@DataField(name = "类名", order = 0)
	private String name;

	/**
	 * 标题名称，作为描述性的名称；
	 */
	@NotBlank
	@DataLabel
	@DataField(name = "标签名", order = 1)
	private String topic;
	
	/**
	 * 描述；
	 */
	@DataType(contentType = "plain;multiline=true")
	@DataField(name = "描述", order = 2)
	private String description;
	
	/**
	 * 数据字段列表；
	 */
	@DataComposite(model = ModelFieldMetadata.class, interfase = ModelFieldMetadata.class)
	@DataField(name = "字段列表", order = 10)
	private ModelFieldMetadata[] fields;

	/**
	 * 唯一主键字段；
	 * <p>
	 * 
	 * 如果没有，则为 null；
	 * <p>
	 */
	@DataReference(model = ModelFieldMetadata.class, interfase = ModelFieldBaseSettings.class)
	@DataField(name = "唯一主键", order = 20)
	private String primaryKey;

	/**
	 * 联合主键字段列表；
	 * <p>
	 * 
	 * 如果没有，则为 null；
	 * <p>
	 */
	@DataReference(model = ModelFieldMetadata.class, interfase = ModelFieldBaseSettings.class)
	@DataField(name = "联合主键", order = 21)
	private String[] unionKeys;


	/**
	 * 标签字段；
	 * <p>
	 * 
	 * 如果没有，则为 null；
	 * <p>
	 * TODO: 引用字段列表；
	 */
	@DataReference(model = ModelFieldMetadata.class, interfase = ModelFieldBaseSettings.class)
	@DataField(name = "标题字段", order = 22)
	private String labelKey;

	/**
	 * 是否自动声明为同名接口；
	 */
	@DefaultBoolean(false)
	@DataType(contentType = "enum;strict=true;false='类';true='类和接口'")
	@DataField(name = "类型发布", order = 30)
	private boolean interfaced = false;


	/**
	 * 实现的数据接口的名称列表；
	 * 
	 * <p>
	 * 数据模型实现的接口列表在上下文中有对应的接口类型，因而不应该简单地修改此字段的值，因此字段标注为“只读”；
	 */
	@DataReference(model = DataInterfaceMetadata.class, interfase = DataInterfaceMetadata.class)
	@DataField(name = "实现接口", order = 40, readonly=true)
	private String[] interfaces;

	@Override
	public String getName() {
		return name;
	}

	@Override
	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String getPrimaryKey() {
		return primaryKey;
	}

	@Override
	public void setPrimaryKey(String primaryKey) {
		this.primaryKey = primaryKey;
	}

	@Override
	public String[] getUnionKeys() {
		return unionKeys;
	}

	@Override
	public void setUnionKeys(String[] unionKeys) {
		this.unionKeys = unionKeys;
	}

	@Override
	public ModelFieldMetadata[] getFields() {
		return fields;
	}

	@Override
	public void setFields(ModelFieldMetadata[] fields) {
		this.fields = fields;
	}

	@Override
	public String[] getInterfaces() {
		return interfaces;
	}

	@Override
	public void setInterfaces(String[] interfaces) {
		this.interfaces = interfaces;
	}

	@Override
	public String getLabelKey() {
		return labelKey;
	}

	@Override
	public void setLabelKey(String labelKey) {
		this.labelKey = labelKey;
	}

	@Override
	public String getTopic() {
		return topic;
	}

	@Override
	public void setTopic(String topic) {
		this.topic = topic;
	}

	@Override
	public boolean isInterfaced() {
		return interfaced;
	}

	@Override
	public void setInterfaced(boolean interfaced) {
		this.interfaced = interfaced;
	}

	@Override
	public String getDescription() {
		return description;
	}

	@Override
	public void setDescription(String description) {
		this.description = description;
	}

}
